<script>
$(document).ready(function(){
	getAllData();
	$("#outForm").ajaxForm({
    	dataType:  'json',
    	success: showResponse
    });

	function showResponse(res) {
		if (res.error) {
			var message = '';
			$.each(res.error,function(i,val){
				$.each(val,function(ii,vv){
					$("#"+i+"-"+ii).addClass('ui-state-error');
					$.each(vv,function(iii,vvv){
						message += $("#"+ii+"-label label").html()+': '+ vvv+ "\n";
					});
				});
			});
			jAlert(message, '<?php echo $this->translate('checking errors')?>');
		}
		else{
			//$("#outForm input:text").val('').attr('disabled','');
			//$("#out-SaveBtn").attr('disabled','true');
			$("#out-CancelBtn").trigger('click');
			getAllData();
			$("#out-class_id").trigger('change');
		}
		$('#move-out-data').unblock();
	}


	function getAllData(){
		var year_semester = $("#out-year_semester").val();
		$("#out-year-semester-span").html($("#out-year_semester option:selected").text());
		//$("#data-section").hide();
		$.get('<?php echo $this->route('getclass')?>',{year_semester:year_semester},function(data){
			ss = '<option value=""><?php echo $this->translate('choose a class')?></option>'+data;
			$("#out-class_id").html(ss);
		});

		$.get('<?php echo $this->route('get-student')?>',{year_semester:year_semester, kind:'out'},function(data){
			$("#out-student-list").html(data);
		});
		$("#out-student_sn").trigger('change');
	}

	$("#out-SaveBtn").click(function(){
		$('#move-out-data').block({message:'<h1><?php echo $this->translate('Data setting ..')?></h1>',  border: '3px solid #f00'});
		$("#outForm").submit();
	});

	$("#out-class_id").change(function(){
		var year_semester = $("#out-year_semester").val();
		var class_id=$(this).val();
		$.get('<?php echo $this->route('getstudents')?>',{year_semester:year_semester,class_id:class_id},function(data){
			var ss = '<option value=""><?php echo $this->translate('choose a student')?></option>'+data;
			$("#out-student_sn").html(ss);
		});
		$("#out-student_sn").html('');
		$("#out-student_sn").trigger('change');
	});

	$("#out-year_semester").change(function(){
		$("#out-student_sn").html('');
		$("#out-student_sn").trigger('change');
		$("#out-CancelBtn").trigger('click');
		getAllData();
	});

	$("#out-student_sn").change(function(){
		if ($(this).val())
			$("#out-SaveBtn").attr('disabled','');
		else
			$("#out-SaveBtn").attr('disabled','disabled');
	});

	$("#out-CancelBtn").click(function(){
		$(".ui-state-error").removeClass('ui-state-error ');
		$("#outForm").attr('action','<?php echo $this->route('moveout-set')?>');
		$("#outForm input:text").val('').attr('disabled','');
		$("#outForm input:hidden").val('');
		$("#out-SaveBtn").attr('disabled','disabled');
    	$("#out-CancelBtn").attr('disabled','disabled');
    	$("#out-class_id").attr('disabled','');
		$("#out-student_sn").attr('disabled','');
    	$("#edit-message").html('');
	});
	$("#out-zoom-in").click(function(){
		$.openDOMWindow({
	        loader:1,
	        loaderImagePath:'animationProcessing.gif',
	        loaderHeight:16,
	        loaderWidth:17,
	        width : 960,
	        windowSourceID:'#out-student-list'
	    });
	});
});
</script>
<style>
#out-data {margin:5px;border:thin #ccc solid; padding:5px}
#out-listTable {float:left;margin-left:10px;border:thin #ccc solid; padding:5px}
#out-student-list {overflow: auto;height:350px;width:480px;background:#ffe;border:thin solid #ccc;padding:3px;}
#out-student-list table {white-space: nowrap;}
#select-section {margin:5px;}

</style>

<div id="move-out-data">
<form action="<?php echo $this->route('moveout-set')?>"  method="post" id="outForm" >
<div id="select-section">
<select name="year_semester" id="out-year_semester">
<?php echo $this->YearSemesterOptions($this->year_semester)?>
</select>
<select name="class_id" id="out-class_id">

</select>
<select id="out-student_sn" name="student_sn"></select>
<input type="button" id="out-SaveBtn" value="<?php echo $this->translate('save')?>" disabled="disabled"/>
<input type="button" id="out-CancelBtn" value="<?php echo $this->translate('cancel')?>" disabled="disabled"/>
<span id="edit-message" style="margin-left:5px; background:#ffa;padding:3px;border: solid thin #ccc"></span>
</div>
<div id="out-data">
<div id="out-dataForm" style="float:left;">
<div style="float:left">
<?php echo $this->form->causation_kind?>
<?php echo $this->form->date?>
<?php echo $this->form->county?>
<?php echo $this->form->school_name?>
<?php echo $this->form->school_id?>
</div>
<div style="float:left">
<?php echo $this->form->causation?>
<?php echo $this->form->approve_organ?>
<?php echo $this->form->approve_date?>
<?php echo $this->form->approve_word?>
<?php echo $this->form->approve_number?>
</div>
<div style="clear:both"></div>
</div>


<div id="out-listTable" style="float:left ;margin-left:10px">
<h2><span id="out-year-semester-span"></span> <?php echo $this->translate('all transfer out data')?>
<img  id="out-zoom-in" src="<?php echo $this->baseUrl?>/images/zoom-in.png"  style="margin-left:5px" />
</h2>
<div id="out-student-list"></div>
</div>
<div style="clear:both"></div>
</div>
<input type="hidden" id="move_out-sn" name="sn" />
</form>

</div>
